.SUFFIXES: .cpp .o
.PHONY: cegui
TARGET_OS = $(shell uname -s)
CC        = g++
CFLAGS    = -g -O2 -Wno-deprecated -Wno-write-strings -I./tinyxml/ -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT

OBJ_FILE  = main.o Sound.o network.o engine.o renderer.o timer.o hitbox.o logic.o Map.o MapObstacle.o Fighter.o Attacks.o Beam.o playerControlledShip.o opponent.o ChasingAI.o circleAI.o blackhole.o ./tinyxml/tinyxml.o ./tinyxml/tinyxmlerror.o ./tinyxml/tinystr.o ./tinyxml/tinyxmlparser.o
EXE_FILE  = game

#set libs based on target platform
#note that all spaces are taken into account in the coonditional arguments
#this includes spaces before variables, such as ( $(TARGET_OS),Linux) ( $(TARGET_OS), Linux ) ($(TARGET_OS), Linux)
#will all check different values due to whitespace being appended to the arguments!!!!
ifeq  ($(TARGET_OS),Darwin)
	LIB	  = -lSDL -lSDL_image -lSDL_mixer -framework OpenGL -framework Cocoa -lSDL_net -lSDLmain -L./tinyxml
else ifeq ($(TARGET_OS),Linux)
	LIB	  = -lSDL -lSDL_image -lSDL_mixer -lGL -lSDL_net -L./tinyxml
endif


${EXE_FILE}: ${OBJ_FILE}
		${CC} ${FLAGS} -o ${EXE_FILE} ${OBJ_FILE} ${LIB} -lpthread


.cpp.o: 
	${CC} ${CFLAGS} -c $< -o $@

clean:
		rm -f ${EXE_FILE}
		rm -f *.o
		rm -f log.txt
clean-cegui:
	find ./gui/ ! -name  "CEGUI-0.7.4.tar.gz" ! -name "gui" -delete


main.o: main.cpp 
network.o: network.h network.cpp
engine.o : Fighter.o engine.h engine.cpp
renderer.o : renderer.h renderer.cpp
timer.o: timer.h timer.cpp 
hitbox.o: hitbox.cpp
logic.o : sprite.h logic.h logic.cpp
Map.o : MapObstacle.o Map.h Map.cpp
MapObstacle.o : MapTile.h MapObstacle.h MapObstacle.cpp
Fighter.o: Attacks.o Fighter.cpp
Attacks.o: sprite.h renderer.o Beam.o Fighter.o Attacks.cpp
Beam.o: sprite.h Beam.cpp
playerControlledShip.o: playerControlledShip.cpp
opponent.o: Fighter.o opponent.cpp 
sprite.gch: sprite.h
Sound.o: Sound.cpp
blackhole.o: blackhole.cpp
ChasingAI.o: ChasingAI.cpp
circleAI.o: circleAI.cpp
./tinyxml/tinyxml.o : tinyxml/tinyxml.cpp
./tinyxml/tinyxmlerror.o : tinyxml/tinyxmlerror.cpp
./tinyxml/tinystr.o : tinyxml/tinystr.cpp
./tinyxml/tinyxmlparser.o: tinyxml/tinyxmlparser.cpp

cegui:
	tar -xzf gui/CEGUI-0.7.4.tar.gz --strip-components=1 -C gui/
	cd gui && ./configure --exec-prefix=$(PWD) --prefix=$(PWD) --with-default-image-codec=STBImageCodec --enable-shared --disable-samples && make install



